package ais.dcproject.entities;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class FirstTest {
	
	@SuppressWarnings("deprecation")
	public static void main(String[] args){
		//负责管理Hibernate的配置信息
		Configuration config = new Configuration().configure();
		
		//根据config建立SessionFactory
		//SessionFactory将用于建立Session
		SessionFactory sessionFactory = config.buildSessionFactory();
		
		//生成数据
		Batch batch = new Batch();
		batch.setName("2009级");
		
		//开启Session，相当于JDBC的Connection
		Session session = sessionFactory.openSession();
		
		String sql = "from Batch batch";
		List list = session.createQuery(sql).list();
		
		Iterator iterator = list.iterator();
		
		Batch batchs = null;
		while(iterator.hasNext()){
			batchs = (Batch) iterator.next();
			
			System.out.println(batchs.getId() + "  " + batchs.getName());
		}
		
//		//Transaction 相当于开启一次事务处理
//		
//		Transaction tx = session.beginTransaction();
//		
//		session.save(batch);
//		tx.commit();
//		
//		session.close();
//		
//		sessionFactory.close();
//		
//		System.out.println("Action OK!");
		
	}
}
